import {
  COLOR_CONFIG,
  DEFECT_SCENE_STATE_COLOR,
  QUESTION_REPAIR_COLOR,
  TABLE_ALIGN,
  TABLE_SHOW_TYPE
} from "@/constantData";
import {isArr} from "@/utils/arrayUtil";
import {HANDEL_CODE_CONFIG} from "@/views/checkPage/config/eventConfig";

//  获取状态颜色
const getStateColor = (value, colorList) => {
  const defaultColor = COLOR_CONFIG.BLUE;
  if (value == null || value == '' || !isArr(colorList)) {
    return defaultColor
  }
  let colorItem = colorList.find(item => item.values.some(dataItem => dataItem == value));
  return colorItem ? colorItem.color : defaultColor
};

// 企业名称
const BELONG_ORG_NAME = {
  width: 150,
  align: TABLE_ALIGN.LEFT,
  prop: 'belongOrgName',
  label: '企业名称',
  sortable:'custom',
  type: TABLE_SHOW_TYPE.TXT,
};

// 隐患所属大类
const QUESTION_PARENT_TYPE_NAME = {
  width: 150,
  align: TABLE_ALIGN.LEFT,
  prop: 'parentTypeName',
  label: '隐患所属大类',
  sortable:'custom',
  type: TABLE_SHOW_TYPE.TXT,
};

// 隐患所属子类
const QUESTION_TYPE_NAME = {
  width: 150,
  align: TABLE_ALIGN.LEFT,
  prop: 'childTypeName',
  sortable:'custom',
  label: '隐患所属子类',
  type: TABLE_SHOW_TYPE.TXT,
};

//  隐患类别
const QUESTION_ITEM_NAME = {
  width: 200,
  align: TABLE_ALIGN.LEFT,
  prop: 'typeName',
  sortable:'custom',
  label: ' 隐患类别',
  type: TABLE_SHOW_TYPE.TXT,
};

// 隐患来源
const QUESTION_SOURCE_NAME = {
  width: 120,
  align: TABLE_ALIGN.LEFT,
  prop: 'questionSourceName',
  sortable:'custom',
  label: '隐患来源',
  type: TABLE_SHOW_TYPE.TXT,
};

// 隐患来源机构
const QUESTION_SOURCE_ORG_NAME = {
  width: 150,
  align: TABLE_ALIGN.LEFT,
  prop: 'questionSourceOrgName',
  sortable:'custom',
  label: '隐患来源机构',
  type: TABLE_SHOW_TYPE.TXT,
};

// 隐患描述
const QUESTION_DESC = {
  align: TABLE_ALIGN.LEFT,
  prop: 'questionDesc',
  sortable:'custom',
  label: '隐患描述',
  type: TABLE_SHOW_TYPE.TXT,
};

// 复核状态
const SCENE_STATE_NAME = {
  width: 120,
  align: TABLE_ALIGN.CENTER,
  prop: 'sceneStateName',
  propValue: 'sceneState',
  getStateColor,
  colorList: DEFECT_SCENE_STATE_COLOR,
  label: '复核状态',
  type: TABLE_SHOW_TYPE.STATE,
};

// 整改状态
const REPAIR_STATE_NAME = {
  width: 120,
  align: TABLE_ALIGN.CENTER,
  prop: 'repairStateName',
  propValue: 'repairState',
  getStateColor,
  colorList: QUESTION_REPAIR_COLOR,
  sortable:'custom',
  label: '整改状态',
  type: TABLE_SHOW_TYPE.STATE,
};

// 整改进度
const SCHEDULE = {
  width: 180,
  align: TABLE_ALIGN.CENTER,
  prop: 'schedule',
  sortable:'custom',
  label: '整改进度',
  type: TABLE_SHOW_TYPE.SCHEDULE,
};

const QUESTION_TABLE_CONFIG = {
  //   自查
  [HANDEL_CODE_CONFIG.SELF_INSPECTION]: [
    QUESTION_PARENT_TYPE_NAME,
    QUESTION_TYPE_NAME,
    QUESTION_ITEM_NAME,
    QUESTION_DESC,
    REPAIR_STATE_NAME,
    SCHEDULE,
  ],
  //  隐患整改
  [HANDEL_CODE_CONFIG.HIDDEN_DANGER_RECTIFICATION]: [
    QUESTION_PARENT_TYPE_NAME,
    QUESTION_TYPE_NAME,
    QUESTION_ITEM_NAME,
    QUESTION_SOURCE_NAME,
    QUESTION_SOURCE_ORG_NAME,
    QUESTION_DESC,
    SCENE_STATE_NAME,
    REPAIR_STATE_NAME,
    SCHEDULE,
  ],
  //  抽查
  [HANDEL_CODE_CONFIG.SPOT_CHECK]: [
    BELONG_ORG_NAME,
    QUESTION_PARENT_TYPE_NAME,
    QUESTION_TYPE_NAME,
    QUESTION_ITEM_NAME,
    QUESTION_DESC,
    REPAIR_STATE_NAME,
    SCHEDULE,
  ],
  //  督查
  [HANDEL_CODE_CONFIG.SUPERVISE_AND_EXAMINE]: [
    BELONG_ORG_NAME,
    QUESTION_PARENT_TYPE_NAME,
    QUESTION_TYPE_NAME,
    QUESTION_ITEM_NAME,
    QUESTION_DESC,
    REPAIR_STATE_NAME,
    SCHEDULE,
  ],
  //  企业 -- 隐患初审
  [HANDEL_CODE_CONFIG.QY_HIDDEN_DANGER_REVIEW]: [
    QUESTION_PARENT_TYPE_NAME,
    QUESTION_TYPE_NAME,
    QUESTION_ITEM_NAME,
    QUESTION_SOURCE_NAME,
    QUESTION_SOURCE_ORG_NAME,
    QUESTION_DESC,
    SCENE_STATE_NAME,
  ],
  //  企业 -- 隐患复审
  [HANDEL_CODE_CONFIG.JG_HIDDEN_DANGER_REVIEW_FS]: [
    QUESTION_PARENT_TYPE_NAME,
    QUESTION_TYPE_NAME,
    QUESTION_ITEM_NAME,
    QUESTION_SOURCE_NAME,
    QUESTION_SOURCE_ORG_NAME,
    QUESTION_DESC,
    SCENE_STATE_NAME,
  ],
  //  监管部门 -- 隐患复核
  [HANDEL_CODE_CONFIG.JG_HIDDEN_DANGER_REVIEW]: [
    QUESTION_PARENT_TYPE_NAME,
    QUESTION_TYPE_NAME,
    QUESTION_ITEM_NAME,
    QUESTION_SOURCE_NAME,
    QUESTION_SOURCE_ORG_NAME,
    QUESTION_DESC,
    SCENE_STATE_NAME,
  ],

  //  隐患查询
  [HANDEL_CODE_CONFIG.HIDDEN_DANGER_QUERY]: [
    QUESTION_PARENT_TYPE_NAME,
    QUESTION_TYPE_NAME,
    QUESTION_ITEM_NAME,
    QUESTION_SOURCE_NAME,
    QUESTION_SOURCE_ORG_NAME,
    QUESTION_DESC,
    REPAIR_STATE_NAME
  ],
};

const getQuestionTableColum = handelCode => {
  return QUESTION_TABLE_CONFIG[handelCode] || []
}

export {getQuestionTableColum}
